/**
 * 安卓白金英雄坛制作组 <br>
 * 文件名：BLGFileIO.java <br>
 * 创建时间：2013-5-30 下午6:17:31 <br>
 * 所属项目：GmudEX <br>
 * @author 12548 <br>
 */
package lostland.gmud.exv2.blgframework.impl;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.AssetManager;
import android.preference.PreferenceManager;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import lostland.gmud.exv2.blgframework.IFileIO;


/**
 * 类名：BLGFileIO <br>
 * 说明：IO操作
 *
 * @author 12548
 */
public class BLGFileIO implements IFileIO {

	Context context;
	AssetManager assets;
	public String externalStoragePath;

	public BLGFileIO(Context context) {
		this.context = context;
		this.assets = context.getAssets();
//		this.externalStoragePath= Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator;
		File f = context.getExternalFilesDir(null);
		String s = f.getAbsolutePath();
		this.externalStoragePath = s + File.separator;
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.blgframework.IFileIO#readAsset(java.lang.String)
	 */
	@Override
	public InputStream readAsset(String fileName) throws IOException {
		return assets.open(fileName);
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.blgframework.IFileIO#readFile(java.lang.String)
	 */
	@Override
	public InputStream readFile(String fileName) throws IOException {
		return new FileInputStream(externalStoragePath + fileName);
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.blgframework.IFileIO#writeFile(java.lang.String)
	 */
	@Override
	public OutputStream writeFile(String fileName) throws IOException {
		return new FileOutputStream(externalStoragePath + fileName);
	}

	@Override
	public SharedPreferences getPreferences() {
		return PreferenceManager.getDefaultSharedPreferences(context);
	}

}
